package com.imxinxin.common.tools.string;

import java.util.UUID;

public class StringTool {
    public static boolean isEmpty(String s) {
        return s == null || "".equals(s.trim());
    }

    public static boolean isEmpty(Object s) {
        return s == null || "".equals(s.toString().trim());
    }

    public static boolean isEmpty(String... ss) {
        if (ss == null || ss.length == 0) return true;
        for (String s : ss) {
            if (isEmpty(s)) return true;
        }
        return false;
    }

    public static boolean isEmpty(Object... ss) {
        if (ss == null || ss.length == 0) return true;
        for (Object s : ss) {
            if (isEmpty(s)) return true;
        }
        return false;
    }


    /**
     * 获取char的所有拼音数组
     *
     * @param c
     * @return
     */
    public static String[] toAllPinyin(char c) {
        return null;
    }

    public static String getInitial(String s, String ifNull) {
        return getInitial(s.charAt(0), ifNull);
    }

    public static String getInitial(char c, String ifNull) {
        String[] ss = toAllPinyin(c);
        if (ss == null || ss.length == 0) {
            return ifNull;
        }
        return ss[0].substring(0, 1).toUpperCase();
    }

    /**
     * String转拼音
     *
     * @param s
     * @return
     */
    public static String toPinyin(String s) {
        char[] cs = s.toCharArray();
        StringBuilder sb = new StringBuilder();
        String[] ss;
        for (char c : cs) {
            ss = toAllPinyin(c);
            if (ss == null || ss.length == 0) {
                sb.append(c);
                continue;
            }
            sb.append(ss[0]).append(" ");
        }
        return sb.toString().trim();
    }

    /**
     * 获取无-的uuid
     *
     * @return
     */
    public static String uuid() {
        return UUID.randomUUID().toString().replace("-", "");
    }


    /**
     * 首字母小写
     *
     * @param s
     * @return
     */
    public static String firstLowerCase(String s) {
        if (isEmpty(s)) {
            return s;
        }
        return s.substring(0, 1).toLowerCase() + s.substring(1);
    }

    /**
     * @param no      号
     * @param s       截取前几位
     * @param e       截取后几位
     * @param padding 中间填充
     * @return
     */
    public static String getShow(String no, Integer s, Integer e, String padding) {
        String noShow;
        if (StringTool.isEmpty(no)) {
            return null;
        }

        int i = no.length() / 2;

        if (s == null) {
            s = 0;
        } else if (s > i - 1) {
            s = i - 1;
        }

        if (e == null || e > (no.length() - i - 2)) {
            e = no.length() - i - 2;
        }
        if (padding == null) {
            padding = "";
        }
        if (s < 0 || e < 0) {
            noShow = "*";
        } else {
            noShow = no.substring(0, s) + padding + no.substring(no.length() - e);
        }
        return noShow;
    }

    /**
     * 如果跟其中一个相同就是true
     *
     * @param obj
     * @param objs
     * @return
     */
    public static boolean equalsOne(Object obj, Object... objs) {
        if (obj == null) {
            if (objs == null) {
                return true;
            }
            for (Object o : objs) {
                if (o == null) {
                    return true;
                }
                return false;
            }
        }

        for (Object o : objs) {
            if (obj.equals(o)) {
                return true;
            }
        }
        return false;

    }

    /**
     * 如果跟其中一个相同就是true 如果为空则false
     *
     * @param obj
     * @param objs
     * @return
     */
    public static boolean equalsOneAndNotNull(Object obj, Object... objs) {
        if (obj == null) {
            return false;
        }
        for (Object o : objs) {
            if (obj.equals(o)) {
                return true;
            }
        }
        return false;

    }

    /**
     * 首字母大写
     *
     * @param field
     * @return
     */
    public static String titleCase(String field) {
        if (isEmpty(field)) {
            return field;
        }
        if (field.length() == 1) {
            return field.toUpperCase();
        }
        return field.substring(0, 1).toUpperCase() + field.substring(1);
    }

    /**
     * 获取String字段的get方法
     *
     * @return
     */
    public static String getGetMethod(String field) {
        return "get" + titleCase(field);
    }

    /**
     * 获取String字段的set方法
     *
     * @return
     */
    public static String getSetMethod(String field) {
        return "set" + titleCase(field);
    }

    public static String camel2under(String c) {
        String separator = "_";
        c = c.replaceAll("([a-z])([A-Z])", "$1" + separator + "$2").toLowerCase();
        return c;
    }

    public static void main(String[] args) {
        System.out.println(camel2under("plusSaveMoneyInfo"));
    }
}
